#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
#  Project: Kelindo - Unsupervised Music Organizer  
#  Author: Nicola Bicocchi <nicola.bicocchi@gmail.com>, Nicolo' Torreggiani <nicolo.torreggiani@gmail.com>, Gianluca Puglia <gianluca.puglia@gmail.com>, Matteo Senardi <pualien@gmail.com>
#  Copyright: 2013 Nicola Bicocchi, Nicolo' Torreggiani, Gianluca Puglia, Matteo Senardi
#  License: GPL-2+
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.
# 
# On Debian GNU/Linux systems, the full text of the GNU General Public License
# can be found in the file /usr/share/common-licenses/GPL-2.
##

import os
import locale

if os.name == "nt":
    from win32com.shell import shellcon, shell


class Version(tuple):
    """Represent the version of a dependency as a tuple"""

    def __new__(cls, *args):
        # Support tuple or varargs instantiation
        value = args[0] if len(args) == 1 else args
        return tuple.__new__(Version, value)

    def human_version(self):
        return ".".join(map(str, self))

    def __str__(self):
        return self.human_version()


class MinVersions(object):
    """Dependency requirements for Quod Libet / Ex Falso"""
    PYTHON = Version(2, 6)
    PYGTK = Version((2, 16))
    MUTAGEN = Version(1, 14)
    REQUESTS = Version(1, 1)

VERSION_TUPLE = Version(1, 0, 0)
VERSION = str(VERSION_TUPLE)

PROCESS_TITLE_GK = "gKelindo"

# expanduser doesn't work with unicode on win...
if os.name == "nt":
    # the last 0 means SHGFP_TYPE_CURRENT
    HOME = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, 0, 0)
else:
    HOME = os.path.expanduser("~")

if os.name == "nt":
    USERDIR = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
    USERDIR = os.path.join(USERDIR, "Kelindo")
else:
    USERDIR = os.path.join(HOME, ".kelindo")
    
CONFIG = os.path.join(USERDIR, "config")
attempts = ['Music', 'Desktop', HOME, ]        
for attempt in attempts:
    OUTPUTDIR = os.path.join(HOME, attempt)
    if os.path.exists(OUTPUTDIR):
        break

BASEDIR = os.path.dirname(os.path.realpath(__file__))
IMAGEDIR = os.path.join(BASEDIR, "images")

# about dialog, --version etc.
WEBSITE = "http://code.google.com/p/kelindo/"
HELPSITE = "http://code.google.com/p/kelindo/wiki/Tutorial"
COPYRIGHT = """\
Copyright © 20013-2013 
Nicola Bicocchi
Gianluca Puglia
Matteo Senardi
Nicolò Torreggiani
"""

# Email used as default for reading/saving per-user data in tags, etc.
EMAIL = os.environ.get("EMAIL", "nicola.bicocchi@gmail.com")

# Displayed as registered / help email address
SUPPORT_EMAIL = "nicola.bicocchi@gmail.com"

AUTHORS = sorted("""\
Nicola Bicocchi
Gianluca Puglia
Matteo Senardi
Nicolò Torreggiani
""".strip().split("\n"))

TRANSLATORS = sorted("""
""".strip().splitlines())

ARTISTS = sorted("""\
""".strip().split("\n"))

MENU = """<ui>
</ui>"""

try:
    ENCODING = locale.getpreferredencoding()
except locale.Error:
    ENCODING = "utf-8"

# http://developer.gnome.org/doc/API/2.0/glib/glib-running.html
if "G_FILENAME_ENCODING" in os.environ:
    FSCODING = os.environ["G_FILENAME_ENCODING"].split(",")[0]
    if FSCODING == "@locale":
        FSCODING = ENCODING
elif "G_BROKEN_FILENAMES" in os.environ:
    FSCODING = ENCODING
else:
    FSCODING = "utf-8"

del(os)
del(locale)
